home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performCreateDisplayLayer.me < prev    next >
Encoding:
Text File  |  2003-07-17  |  10.8 KB  |  427 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  October 30, 1998
  22. //
  23. //  Description:
  24. //
  25. // An option window used to create a named displayLayer.
  26. // A displayLayer is a grouping of DAG objects used to control drawing.
  27. //
  28.  
  29. //
  30. //  Procedure Name:
  31. //      setOptionVars
  32. //
  33. //  Description:
  34. //        Initialize the option values.
  35. //
  36. //  Input Arguments:
  37. //        Whether to set the options to default values.
  38. //
  39. //  Return Value:
  40. //      None.
  41. //
  42. proc setOptionVars(int $forceFactorySettings)
  43. {
  44.     //    Display layer base index
  45.     //
  46.     if ($forceFactorySettings || !`optionVar -exists displayLayerBase`) {
  47.         optionVar -intValue displayLayerBase 1;
  48.     }
  49.  
  50.     //    Set to Current flag
  51.     //
  52.     if ($forceFactorySettings || !`optionVar -exists displayLayerCurrent`) {
  53.         optionVar -intValue displayLayerCurrent false;
  54.     }
  55.  
  56.     //    Contents flag
  57.     //
  58.     if ($forceFactorySettings || !`optionVar -exists displayLayerContents`) {
  59.         optionVar -intValue displayLayerContents 1;
  60.     }
  61. }
  62.  
  63. //
  64. //  Procedure Name:
  65. //      createDisplayLayerSetup
  66. //
  67. //  Description:
  68. //        Update the state of the option box UI to reflect the option values.
  69. //
  70. //  Input Arguments:
  71. //      parent               - Top level parent layout of the option box UI.
  72. //                             Required so that UI object names can be 
  73. //                             successfully resolved.
  74. //
  75. //    forceFactorySettings - Whether the option values should be set to
  76. //                             default values.
  77. //
  78. //  Return Value:
  79. //      None.
  80. //
  81. global proc createDisplayLayerSetup(string $parent, int $forceFactorySettings)
  82. {
  83.     // Retrieve the option settings
  84.     //
  85.     setOptionVars( $forceFactorySettings );
  86.     
  87.     // Layer name
  88.     textFieldGrp -e -text "layer1" displayLayerNameWidget;    
  89.  
  90.     // Base layer index
  91.     int $base = `optionVar -q displayLayerBase`;
  92.     intFieldGrp -e -v1 $base displayLayerBaseWidget;    
  93.  
  94.     // Contents flag
  95.     int $contents = `optionVar -q displayLayerContents`;
  96.     radioButtonGrp -e -sl $contents contentsRadio;
  97.  
  98.     // Set to Current flag
  99.     int $current = `optionVar -q displayLayerCurrent`;
  100.     checkBoxGrp -e -v1 $current currentCheck;
  101.  
  102.     setParent $parent;
  103. }
  104.  
  105. //
  106. //  Procedure Name:
  107. //      createDisplayLayerCallback
  108. //
  109. //  Description:
  110. //        Update the option values with the current state of the option box UI.
  111. //
  112. //  Input Arguments:
  113. //      parent - Top level parent layout of the option box UI.  Required so
  114. //               that UI object names can be successfully resolved.
  115. //
  116. //    doIt   - Whether the command should execute.
  117. //
  118. //  Return Value:
  119. //      None.
  120. //
  121. global proc createDisplayLayerCallback(string $parent, int $doIt)
  122. {
  123.     setParent $parent;
  124.  
  125.     //    Contents flag
  126.     //
  127.     optionVar -iv displayLayerContents `radioButtonGrp -q -sl contentsRadio`;
  128.  
  129.     //    'Make current' flag
  130.     //
  131.     optionVar -iv displayLayerCurrent `checkBoxGrp -q -v1 currentCheck`;
  132.  
  133.     //    Base layer index
  134.     //
  135.     optionVar -iv displayLayerBase `intFieldGrp -q -v1 displayLayerBaseWidget`;
  136.  
  137.     if ($doIt) {
  138.         performCreateDisplayLayer 0; 
  139.         addToRecentCommandQueue "performCreateDisplayLayer 0" "CreateDisplayLayer";
  140.     }
  141. }
  142.  
  143. //
  144. //  Procedure Name:
  145. //      createDisplayLayerOptions
  146. //
  147. //  Description:
  148. //        Construct the option box UI.  Involves accessing the standard option
  149. //        box and customizing the UI accordingly.
  150. //
  151. //  Input Arguments:
  152. //      None.
  153. //
  154. //  Return Value:
  155. //      None.
  156. //
  157. proc createDisplayLayerOptions()
  158. {
  159.     //    Name of the command for this option box.
  160.     //
  161.     string $commandName = "createDisplayLayer";
  162.  
  163.     //    Build the option box actions.
  164.     //
  165.     string $callback = ($commandName + "Callback");
  166.     string $setup = ($commandName + "Setup");
  167.  
  168.     //    STEP 1:  Get the option box.
  169.     //    ============================
  170.     //
  171.     //    The value returned is the name of the layout to be used as
  172.     //    the parent for the option box UI.
  173.     //
  174.     string $layout = getOptionBox();
  175.     setParent $layout;
  176.     
  177.     //    STEP 2:  Pass the command name to the option box.
  178.     //    =================================================
  179.     //
  180.     //    Any default option box behaviour based on the command name is set 
  181.     //    up with this call.  For example, updating the 'Help' menu item with
  182.     //    the name of the command.
  183.     //
  184.     setOptionBoxCommandName($commandName);
  185.     
  186.     //    STEP 3:  Activate the default UI template.
  187.     //    ==========================================
  188.     //
  189.     //    Activate the default UI template so that the layout of this 
  190.     //    option box is consistent with the layout of the rest of the 
  191.     //    application.
  192.     //
  193.     setUITemplate -pushTemplate DefaultTemplate;
  194.  
  195.     //    STEP 4: Create option box contents.
  196.     //    ===================================
  197.     
  198.     //    Turn on the wait cursor.
  199.     //
  200.     waitCursor -state 1;
  201.  
  202.     tabLayout -tabsVisible 0 -scrollable 1;
  203.     string $parent = `columnLayout -adjustableColumn 1`;
  204.     string $tabForm = `columnLayout -adjustableColumn true`;
  205.  
  206.     // displayLayer name
  207.     //
  208.     textFieldGrp
  209.         -label "Name"
  210.         displayLayerNameWidget;    
  211.  
  212.     // displayLayer number
  213.     //
  214.     intFieldGrp
  215.         -label "Number"
  216.         displayLayerBaseWidget;    
  217.  
  218.     // Current layer setting option
  219.     //
  220.     checkBoxGrp -numberOfCheckBoxes 1
  221.         -label1 "Make the created display layer current"
  222.         currentCheck;
  223.  
  224.     // Which items to add to the layer
  225.     //
  226.     radioButtonGrp -nrb 3
  227.         -cw 2 80
  228.         -cw 4 160
  229.         -l "Add to new display layer" 
  230.         -la3 "Nothing" "Selected" "Selected and Children"
  231.         -sl (`optionVar -q displayLayerContents`)
  232.         -cc1 "optionVar -iv displayLayerContents 1"
  233.         -cc2 "optionVar -iv displayLayerContents 2"
  234.         -cc3 "optionVar -iv displayLayerContents 3"
  235.         contentsRadio;
  236.  
  237.     //    Turn off the wait cursor.
  238.     //
  239.     waitCursor -state 0;
  240.     
  241.     //    Step 5: Deactivate the default UI template.
  242.     //    ===========================================
  243.     //
  244.     setUITemplate -popTemplate;
  245.  
  246.     //    Step 6: Customize the buttons.  
  247.     //    ==============================
  248.     //
  249.     //    Provide more descriptive labels for the buttons.  This is not 
  250.     //    necessary, but in some cases, for example, a button labelled 
  251.     //    'Create' may be more meaningful to the user than one labelled
  252.     //    'Apply'.
  253.     //
  254.     //    Disable those buttons that are not applicable to the option box.
  255.     //
  256.     //    Attach actions to those buttons that are applicable to the option
  257.     //    box.  Note that the 'Close' button has a default action attached 
  258.     //    to it that will hide the window.  If a a custom action is
  259.     //    attached to the 'Close' button then be sure to call the 'hide the
  260.     //    option box' procedure within the custom action so that the option
  261.     //    box is hidden properly.
  262.  
  263.     //    'Apply' button.
  264.     //
  265.     string $applyBtn = getOptionBoxApplyBtn();
  266.     button -edit
  267.         -label "Create"
  268.         -command ($callback + " " + $parent + " " + 1)
  269.         $applyBtn;
  270.  
  271.     //    'Save' button.
  272.     //
  273.     string $saveBtn = getOptionBoxSaveBtn();
  274.     button -edit 
  275.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  276.         $saveBtn;
  277.  
  278.     //    'Reset' button.
  279.     //
  280.     string $resetBtn = getOptionBoxResetBtn();
  281.     button -edit 
  282.         -command ($setup + " " + $parent + " " + 1)
  283.         $resetBtn;
  284.  
  285.     //    Step 7: Set the option box title.
  286.     //    =================================
  287.     //
  288.     setOptionBoxTitle("Display Layer Options");
  289.  
  290.     //    Step 8: Customize the 'Help' menu item text.
  291.     //    ============================================
  292.     //
  293.     setOptionBoxHelpTag( "" );
  294.  
  295.     //    Step 9: Set the current values of the option box.
  296.     //    =================================================
  297.     //
  298.     eval (($setup + " " + $parent + " " + 0));    
  299.     
  300.     //    Step 10: Show the option box.
  301.     //    =============================
  302.     //
  303.     showOptionBox();
  304. }
  305.  
  306. //
  307. //  Procedure Name:
  308. //      createDisplayLayerHelp
  309. //
  310. //  Description:
  311. //        Return a short description about this command.
  312. //
  313. //  Input Arguments:
  314. //      None.
  315. //
  316. //  Return Value:
  317. //      string.
  318. //
  319. proc string createDisplayLayerHelp()
  320. {
  321.  
  322.     return 
  323.     "  Command: Create Display Layer - create a displayLayer.\n" +
  324.     "Selection: Selected DAG objects are added to the displayLayer.";
  325. }
  326.  
  327. //
  328. //  Procedure Name:
  329. //      assembleCmd
  330. //
  331. //  Description:
  332. //        Construct the command that will apply the option box values.
  333. //
  334. //  Input Arguments:
  335. //      None.
  336. //
  337. proc string assembleCmd()
  338. {
  339.     string $cmd;
  340.  
  341.     setOptionVars(false);
  342.  
  343.     // get the displayLayer name
  344.     string $displayLayerName = "layer1";
  345.     if (`textFieldGrp -exists displayLayerNameWidget`) {
  346.         $displayLayerName = `textFieldGrp -q -text displayLayerNameWidget`;
  347.     }
  348.  
  349.     // get the displayLayer base number
  350.     int $displayLayerBase = `optionVar -q displayLayerBase`;
  351.  
  352.     // create the displayLayer command string
  353.     if (0 == size($displayLayerName)) {
  354.         $displayLayerName = "layer1";
  355.     }
  356.     $displayLayerName = "\"" + $displayLayerName + "\"";
  357.     $cmd = "createDisplayLayer -name " + $displayLayerName
  358.                      + " -number " + $displayLayerBase;
  359.  
  360.     int $contents = `optionVar -q displayLayerContents`;
  361.     int $current = `optionVar -q displayLayerCurrent`;
  362.     if( $contents == 1 )
  363.     {
  364.         $cmd += " -empty";
  365.     }
  366.     else if( $contents == 2 )
  367.     {
  368.         $cmd += " -nr";
  369.     }
  370.     if( $current ) $cmd += " -mc";
  371.  
  372.     return $cmd;
  373. }
  374.  
  375. //
  376. //  Procedure Name:
  377. //      performCreateDisplayLayer
  378. //
  379. //  Description:
  380. //        Perform the create display layer command using the corresponding 
  381. //        option values.  This procedure will also show the option box
  382. //        window if necessary as well as construct the command string
  383. //        that will invoke the createDisplayLayer command with the current
  384. //        option box values.
  385. //
  386. //  Input Arguments:
  387. //      0 - Execute the command.
  388. //      1 - Show the option box dialog.
  389. //      2 - Return the command.
  390. //
  391. global proc string performCreateDisplayLayer(int $action)
  392. {
  393.     string $cmd = "";
  394.  
  395.     switch ($action) {
  396.  
  397.         //    Execute the command.
  398.         //
  399.         case 0:
  400.             //    Get the command.
  401.             //
  402.             $cmd = `assembleCmd`;
  403.  
  404.             //    Execute the command with the option settings.
  405.  
  406.             evalEcho($cmd);
  407.  
  408.             break;
  409.  
  410.         //    Show the option box.
  411.         //
  412.         case 1:
  413.             createDisplayLayerOptions;
  414.             break;
  415.  
  416.         //    Return the command string.
  417.         //
  418.         case 2:
  419.             //    Get the command.
  420.             //
  421.             $cmd = `assembleCmd`;
  422.             break;
  423.     }
  424.     return $cmd;
  425. }
  426.  
  427.